unit aparear_uni;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, DBCtrls, DB, Grids, DBGrids, jpeg;

type
  TfrmAparear_uni = class(TForm)
    sUni: TDataSource;
    Panel1: TPanel;
    DBGrid1: TDBGrid;
    Label1: TLabel;
    lblTexto: TLabel;
    Panel2: TPanel;
    DBNavigator1: TDBNavigator;
    btnGrabar: TBitBtn;
    Panel57: TPanel;
    Image9: TImage;
    Panel58: TPanel;
    Label2: TLabel;
    procedure sUniStateChange(Sender: TObject);
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
    procedure btnGrabarClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure Label2Click(Sender: TObject);
  private
    { Private declarations }
  public
    procedure Entrar(uni, texto: TStringList);
  end;

var
  frmAparear_uni: TfrmAparear_uni;
  uni_auxiliar, texto_auxiliar : TStringList;

implementation

uses MDatos, unidad, Recursos;

{$R *.dfm}

procedure TfrmAparear_uni.Entrar(uni, texto: TStringList);
var
  i: word;
begin
  try
    uni_auxiliar := TStringList.Create;
    texto_auxiliar := TStringList.Create;
    for i:= 0 to uni.Count -1 do
    begin
      uni_auxiliar.Append(uni.Strings [i]);
      texto_auxiliar.Append(texto.Strings [i]);
    end;
    if Datos.cUni.State in [dsInactive] then
      Datos.cUni.Open;
    Datos.cUni.Insert;
    Datos.cUniUNI.AsString := uni_auxiliar.Strings [0];
    lblTexto.Caption := texto_auxiliar.Strings [0];
    btnGrabar.Enabled := Datos.cUni.State in [dsBrowse];
    ShowModal;
  finally
    uni_auxiliar.Free;
    texto_auxiliar.Free;
  end;
end;

procedure TfrmAparear_uni.sUniStateChange(Sender: TObject);
begin
  if frmAparear_uni.Visible then
    btnGrabar.Enabled := Datos.cUni.State in [dsBrowse];
end;

procedure TfrmAparear_uni.DBNavigator1Click(Sender: TObject;
  Button: TNavigateBtn);
begin
  Uni_auxiliar.Delete(0);
  texto_auxiliar.Delete(0);
  if uni_auxiliar.Count > 0 then
  begin
    Datos.cUni.Insert;
    Datos.cUniUNI.AsString := Uni_Auxiliar.Strings [0];
    lblTexto.Caption := texto_auxiliar.Strings [0];
  end;
end;

procedure TfrmAparear_uni.btnGrabarClick(Sender: TObject);
begin
  if Datos.cUni.ChangeCount > 0 then
    if Datos.cUni.ApplyUpdates(0) = 0 then
      Datos.cUni.Refresh;
end;

procedure TfrmAparear_uni.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  CanClose := btnGrabar.Enabled;
end;

procedure TfrmAparear_uni.FormCreate(Sender: TObject);
begin
  Acomodo(frmAparear_uni);
end;

procedure TfrmAparear_uni.Label2Click(Sender: TObject);
begin
  frmUnidad.Entrar;
end;

end.
